﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using CDSysLDManageProject.BYDTableAdapters;

namespace CDSysLDManageProject
{
    public partial class FormClosedCheck : Form
    {
         tbl_usrTableAdapter usr = new tbl_usrTableAdapter();
        public FormClosedCheck()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string password = tbxpass.Text;
            password = GetMd5Str(password);
            int passcount = int.Parse(usr.GetPasswordCount(password).ToString());
                if (passcount>0)
                {
                    StaticArg.CheckStatus = "close";
                    StaticArg.ChangeArg = "OK";
                    this.Close();

                }
                else
                {
                    lbtip.Text = "您输入的密码不对，请重新输入";
                }
        }



        public static string GetMd5Str(string orgpass)
        {

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string pass = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(orgpass)), 4, 8);
            pass = pass.Replace("-", "");
            return pass;
        }

        private void tbxpass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string password = tbxpass.Text;
                password = GetMd5Str(password);
                int passcount = int.Parse(usr.GetPasswordCount(password).ToString());
                if (passcount > 0)
                {
                    StaticArg.CheckStatus = "close";
                    StaticArg.ChangeArg = "OK";
                    this.Close();

                }
                else
                {
                    lbtip.Text = "您输入的密码不对，请重新输入";
                }
            }
        }

        private void tbxpass_TextChanged(object sender, EventArgs e)
        {
            lbtip.Text = "";
        }
            
        }


       

    }

